{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "70dbf198",
   "metadata": {},
   "source": [
    "# 第5周\n",
    "* author:小邱同学\n",
    "* time：第5周周二上午\n",
    "* link: [百度AI开发平台](https://ai.baidu.com/)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd25af57",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66dd81cd",
   "metadata": {},
   "source": [
    "# 图像识别\n",
    "* https://ai.baidu.com/ai-doc/IMAGERECOGNITION/Xk3bcxe21\n",
    "* https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjhhu\n",
    "* https://cloud.baidu.com/doc/IMAGERECOGNITION/s/Kk3bcxbxj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdd73f4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 账号密码\n",
    "API_Key = 6wESwZxKqy83cWrYg0EIKRgx\n",
    "API_Secret = lOBHtua8XnGAZly2ncd35MxQsPXk7yI9"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdf66b2c",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00a1f59e",
   "metadata": {},
   "source": [
    "## 通用物体和场景识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e702619",
   "metadata": {},
   "source": [
    "## （1）接口描述\n",
    "* 该请求用于通用物体及场景识别，即对于输入的一张图片（可正常解码，且长宽比适宜），输出图片中的多个物体及场景标签。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07e622b2",
   "metadata": {},
   "source": [
    "## （2）请求说明\n",
    "* 请求示例\n",
    "> HTTP 方法：POST  \n",
    "> 请求URL： https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general  \n",
    "> URL参数：access_token  通过API Key和Secret Key获取的access_token,参考[“Access Token获取”](https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjhhu)  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41b37407",
   "metadata": {},
   "source": [
    "## （3）获取Access Token\n",
    "\n",
    "* 请求URL数据格式\n",
    "> 向授权服务地址https://aip.baidubce.com/oauth/2.0/token发送请求（推荐使用POST），并在URL中带上以下参数：  \n",
    ">> grant_type： 必须参数，固定为client_credentials；  \n",
    ">> client_id： 必须参数，应用的API Key；  \n",
    ">> client_secret： 必须参数，应用的Secret Key；   "
   ]
  },
  {
   "cell_type": "raw",
   "id": "532b10be",
   "metadata": {},
   "source": [
    "# 例：https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHlA4Fq5eR3LT0vuXV4&client_secret=0rDSjzQ20XUj5itV6WRtznPQSzr5pVw2&"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5e85c99c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.8a7897ade4bcc870b340ab38a41208a4.315360000.1964354046.282335-25863386', 'expires_in': 2592000, 'session_key': '9mzdDAC/flkkTVvFLMli+2EOrOsBC0H9o79huFarEsLbWTO/z9gOdxo0CoXTRJWNorotc6wGS4u/0THC7EvKov85AoGg9w==', 'access_token': '24.75f4375e376f05f1be372c76e5149a82.2592000.1651586046.282335-25863386', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': 'b800824984f424203814f1c83e053911'}\n"
     ]
    }
   ],
   "source": [
    "# 获取access_token示例代码\n",
    "\n",
    "import requests\n",
    "\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token'\n",
    "\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'6wESwZxKqy83cWrYg0EIKRgx',\n",
    "    'client_secret':'lOBHtua8XnGAZly2ncd35MxQsPXk7yI9'\n",
    "}\n",
    "\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6347a799",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.75f4375e376f05f1be372c76e5149a82.2592000.1651586046.282335-25863386'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xiaoqiu_AI = response.json()['access_token']\n",
    "xiaoqiu_AI"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3aa5c62e",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db4d1454",
   "metadata": {},
   "source": [
    "## （3）请求参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "907bfc55",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 截取网页图标\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "835e2957",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>字段</th>\n",
       "      <th>是否必选</th>\n",
       "      <th>类型</th>\n",
       "      <th>说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>log_id</td>\n",
       "      <td>是</td>\n",
       "      <td>uint64</td>\n",
       "      <td>请求标识码，随机数，唯一</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>result</td>\n",
       "      <td>是</td>\n",
       "      <td>dict</td>\n",
       "      <td>识别结果</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>+hasdetail</td>\n",
       "      <td>是</td>\n",
       "      <td>unit</td>\n",
       "      <td>判断是否返回详细信息（除红酒中文名之外的其他字段），含有返回1，不含有返回0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>+wineNameCn</td>\n",
       "      <td>是</td>\n",
       "      <td>string</td>\n",
       "      <td>红酒中文名，无法识别返回空，示例：波斯塔瓦经典赤霞珠品丽珠半甜红葡萄酒</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>+wineNameEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>红酒英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Bostavan...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>+countryCn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>国家中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：摩尔多瓦</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>+countryEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>国家英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Moldova</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>+regionCn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>产区中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：波尔多</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>+regionEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>产区英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Bordeaux</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>+subRegionCn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>子产区中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：梅多克</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>+subRegionEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>子产区英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Medoc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>+wineryCn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>酒庄中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：波斯塔瓦酒庄</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>+wineryEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>酒庄英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Vinaria ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>+classifyByColor</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>酒类型，hasdetail = 0时，表示无法识别，该字段不返回，示例：红葡萄酒</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>+classifyBySugar</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>糖分类型，hasdetail = 0时，表示无法识别，该字段不返回，示例：半甜型</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>+color</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>色泽，hasdetail = 0时，表示无法识别，该字段不返回，示例：宝石红色</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>+grapeCn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>葡萄品种，可能有多种葡萄，hasdetail = 0时，表示无法识别，该字段不返回，示例：品...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>+grapeEn</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>葡萄品种英文名，可能有多种葡萄，hasdetail = 0时，表示无法识别，该字段不返回，示...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>+tasteTemperature</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>品尝温度，hasdetail = 0时，表示无法识别，该字段不返回，示例：6-11℃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>+description</td>\n",
       "      <td>否</td>\n",
       "      <td>string</td>\n",
       "      <td>酒品描述，hasdetail = 0时，表示无法识别，该字段不返回，示例：葡萄酒呈深宝石红色...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   字段 是否必选      类型  \\\n",
       "0              log_id    是  uint64   \n",
       "1              result    是    dict   \n",
       "2          +hasdetail    是    unit   \n",
       "3         +wineNameCn    是  string   \n",
       "4         +wineNameEn    否  string   \n",
       "5          +countryCn    否  string   \n",
       "6          +countryEn    否  string   \n",
       "7           +regionCn    否  string   \n",
       "8           +regionEn    否  string   \n",
       "9        +subRegionCn    否  string   \n",
       "10       +subRegionEn    否  string   \n",
       "11          +wineryCn    否  string   \n",
       "12          +wineryEn    否  string   \n",
       "13   +classifyByColor    否  string   \n",
       "14   +classifyBySugar    否  string   \n",
       "15             +color    否  string   \n",
       "16           +grapeCn    否  string   \n",
       "17           +grapeEn    否  string   \n",
       "18  +tasteTemperature    否  string   \n",
       "19       +description    否  string   \n",
       "\n",
       "                                                   说明  \n",
       "0                                        请求标识码，随机数，唯一  \n",
       "1                                                识别结果  \n",
       "2              判断是否返回详细信息（除红酒中文名之外的其他字段），含有返回1，不含有返回0  \n",
       "3                 红酒中文名，无法识别返回空，示例：波斯塔瓦经典赤霞珠品丽珠半甜红葡萄酒  \n",
       "4   红酒英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Bostavan...  \n",
       "5          国家中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：摩尔多瓦  \n",
       "6       国家英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Moldova  \n",
       "7           产区中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：波尔多  \n",
       "8      产区英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Bordeaux  \n",
       "9          子产区中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：梅多克  \n",
       "10       子产区英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Medoc  \n",
       "11       酒庄中文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：波斯塔瓦酒庄  \n",
       "12  酒庄英文名，hasdetail = 0时，表示无法识别，该字段不返回，示例：Vinaria ...  \n",
       "13           酒类型，hasdetail = 0时，表示无法识别，该字段不返回，示例：红葡萄酒  \n",
       "14           糖分类型，hasdetail = 0时，表示无法识别，该字段不返回，示例：半甜型  \n",
       "15            色泽，hasdetail = 0时，表示无法识别，该字段不返回，示例：宝石红色  \n",
       "16  葡萄品种，可能有多种葡萄，hasdetail = 0时，表示无法识别，该字段不返回，示例：品...  \n",
       "17  葡萄品种英文名，可能有多种葡萄，hasdetail = 0时，表示无法识别，该字段不返回，示...  \n",
       "18         品尝温度，hasdetail = 0时，表示无法识别，该字段不返回，示例：6-11℃  \n",
       "19  酒品描述，hasdetail = 0时，表示无法识别，该字段不返回，示例：葡萄酒呈深宝石红色...  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 图像识别url ：https://ai.baidu.com/ai-doc/IMAGERECOGNITION/Xk3bcxe21\n",
    "pd.read_html('https://ai.baidu.com/ai-doc/IMAGERECOGNITION/Tk3bcxctf')[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc1cd0ed",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5cf1601",
   "metadata": {},
   "source": [
    "## （4）请求代码示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "243fa909",
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('[本地文件]', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '[调用鉴权接口获取的token]'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4475c3db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 18, 'error_msg': 'Open api qps request limit reached'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('06.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload={\n",
    "    'access_token':xiaoqiu_AI,\n",
    "    'image':img,\n",
    "    'baike_num':5\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "d07aaa71",
   "metadata": {},
   "source": [
    "error了 别问 问就是没有给钱！☹"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3cc9a70",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "de7b883e",
   "metadata": {},
   "source": [
    "## 菜品识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39b1c8ad",
   "metadata": {},
   "source": [
    "### （1）请求代码示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16a2581f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "菜品识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/dish\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('[本地文件]', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,\"top_num\":5}\n",
    "access_token = '[调用鉴权接口获取的token]'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "491a074f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 18, 'error_msg': 'Open api qps request limit reached'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "菜品识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/dish\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('01.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "payload={\n",
    "    'access_token':xiaoqiu_AI,\n",
    "    'image':img,\n",
    "    'baike_num':5,\n",
    "    \"top_num\":5\n",
    "}\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e0f71825",
   "metadata": {},
   "source": [
    "别看了 也没给钱！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97aabc01",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97f75705",
   "metadata": {},
   "source": [
    "## 植物识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "484032a9",
   "metadata": {},
   "source": [
    "### （1）请求示例代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "538d6023",
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "植物识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/plant\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('[本地文件]', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '[调用鉴权接口获取的token]'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e8808192",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 18, 'error_msg': 'Open api qps request limit reached'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "植物识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/plant\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('02.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "payload={\n",
    "    'access_token':xiaoqiu_AI,\n",
    "    'image':img,\n",
    "    'baike_num':5,\n",
    "    \"top_num\":5\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "163bbc34",
   "metadata": {},
   "source": [
    "也没给钱！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a63f080",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48fe991b",
   "metadata": {},
   "source": [
    "## 作业：\n",
    "* 尝试使用百度API图像识别其中一个做用户需求分析并设计一个最小可行性应用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "804b6cb5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
